/*
 * This file is a part of the SWFer project.
 *
 * Copyright (C) 2012 Michael Bradshaw <mjbshaw@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef BASICBASETYPES_HPP
#define BASICBASETYPES_HPP

#include <istream>
#include <ostream>

namespace swfer
{

typedef signed __int8 int8_t;
typedef signed __int16 int16_t;
typedef signed __int32 int32_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;

template <typename T>
struct detail_read
{
    static std::istream& read(std::istream& stream, T& v)
    {
        return stream.read(reinterpret_cast<char*>(&v), sizeof(T));
    }
};

template <typename T, std::size_t N>
struct detail_read<T[N]>
{
    static std::istream& read(std::istream& stream, T v[N])
    {
        return stream.read(reinterpret_cast<char*>(v), sizeof(T) * N);
    }
};

template <typename T>
std::istream& read(std::istream& stream, T& v)
{
    return detail_read<T>::read(stream, v);
}




template <typename T>
struct detail_write
{
    static std::ostream& write(std::ostream& stream, const T& v)
    {
        return stream.write(reinterpret_cast<const char*>(&v), sizeof(T));
    }
};

template <typename T, std::size_t N>
struct detail_write<T[N]>
{
    static std::ostream& write(std::ostream& stream, const T v[N])
    {
        return stream.write(reinterpret_cast<const char*>(v), sizeof(T) * N);
    }
};

template <typename T>
std::ostream& write(std::ostream& stream, const T& v)
{
    return detail_write<T>::write(stream, v);
}

}

#endif
